package creational_pattern.prototype_pattern;

import java.util.Date;

public class PrototypePattern {
    public static void main(String[] args) throws CloneNotSupportedException {
        WeeklyLog weeklyLog = new WeeklyLog();
        weeklyLog.setContent("content");
        WeeklyLog clone1 = weeklyLog.clone();
        clone1.setName("amlyc");
        WeeklyLog clone2 = weeklyLog.clone();
        clone2.setDate(new Date());
        WeeklyLog clone3 = weeklyLog.clone();
        System.out.println(clone1);
        System.out.println(clone2);
        System.out.println(clone3);
    }
}
//浅克隆
//引用类型对象和克隆引用类型对象地址相同，基本类型地址不相同
class WeeklyLog implements Cloneable{
    private String name;
    private Date date;
    private String content;

    @Override
    public String toString() {
        return "WeeklyLog{" +
                "name='" + name + '\'' +
                ", date=" + date +
                ", content='" + content + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    protected WeeklyLog clone() throws CloneNotSupportedException {

        return (WeeklyLog)super.clone();
    }
}
